﻿package bdz.projects.slab.core {
	import as3.common.ui.menu.core.MenuComponent;
	import as3.common.ui.menu.events.MenuComponentEvent;
	import as3.common.ui.menu.AnimatedItem;
	import bdz.common.model.AppEnvironment;
	import bdz.dms.core.DMSConfig;
	import bdz.projects.slab.data.SlabSiteData;
	import bdz.projects.slab.managers.SlabSectionManager;
	import flash.display.MovieClip;
	import bdz.common.utils.BitmapUtils;
	import flash.events.*;
	import flash.utils.*;
	import flash.text.*;
	import bdz.projects.slab.data.StaticMenuSet;
	import bdz.common.utils.*;
	import bdz.projects.slab.sections.*;
	import bdz.projects.slab.events.SlabSiteEvent;
	import fl.transitions.easing.*;
	import bdz.common.events.DispatchChannel;
	import flash.net.*;
	import flash.display.*;
	/**
	* ...
	* @author Default
	*/
	public class SlabSite extends MovieClip {
		
		private var siteData:SlabSiteData;
		private var env:AppEnvironment = AppEnvironment.getEnv();
		private var logo:MovieClip;
		private var background:MovieClip;
		private var bounds:MovieClip;
		private var sections:SlabSectionManager;
		
		private var mainMenu:MenuComponent;
		private var subMenu:MenuComponent;
		private var activeLoad:String;
		private var alist:SlabArtistList;
		private var privateAccessButton:PrivateAccessButton;
		private var disabler:MovieClip;
		private var main:MovieClip;
		private var loginScreen:LoginScreen;
		private var videoScreen:SlabVideoPlayer;
		private var onprivate:Boolean = false;
		private var vheight:Number = 710;
		private var vwidth:Number = 966;
		private var footer:SlabFooter;
		private var cbg:*;
		private var cmask:*;
		private var randlines;
		private var preceived:Boolean = false;
		function SlabSite() {
			addEventListener(Event.ADDED_TO_STAGE, initializeSite);
		}
		private function initializeSite(evt:Event):void {
			
			var config:DMSConfig = DMSConfig.getConfig();
			/*debug*/
			//config.baseURL = "http://www.badongers.com/slab/";
			/*bdz preview*/
			//config.baseURL = "";
			/*debug2*/
			//config.baseURL = "http://silverlensphoto.com/slab/";
			
			/*release*/
			config.baseURL = "slab/";
			//
			config.scriptPage = "api.php";
			config.uploadFolder = "assets";
			
			env.addSetting("gallery_id", 1);
			env.addSetting("siteinfo_id", 2);
			env.addSetting("news_id", 3);
			env.addSetting("contact_id", 4);
			env.addSetting("private_id", 5);
			env.addSetting("artists_id", 6);
			env.addSetting("baseURL", config.baseURL);
			siteData = SlabSiteData.getInstance(config);
			
			main = new MovieClip();
			addChild(main);
			
			createElements();
			createListeners();
			onStageResize();
			stage.stageFocusRect = false;
		}
		private function createListeners():void {
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.LOGIN, onLogin);
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.START_LOGIN, onStartLogin);
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.CANCEL_LOGIN, onCancelLogin);
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.SHOW_VIDEO, onShowVideo);
			
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.GO_HOME, onGoHome);
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.GO_TO_SILVERLENS, onExternalLink);
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.GO_TO_INKSURGE, onExternalLink);
			DispatchChannel.getChannel().addEventListener(SlabSiteEvent.GO_TO_NEWS, onExternalLink);
			
			stage.addEventListener(Event.RESIZE, onStageResize);
			siteData.addEventListener(SlabSiteEvent.ARTISTS_LOADED, onSiteDataLoad);
			siteData.addEventListener(SlabSiteEvent.NEWS_LOADED, onSiteDataLoad);
			siteData.addEventListener(SlabSiteEvent.PRIVATE_GALLERY_LOADED, onSiteDataLoad);
			siteData.addEventListener(SlabSiteEvent.PUBLIC_GALLERY_LOADED, onSiteDataLoad);
			siteData.addEventListener(SlabSiteEvent.SITE_INFO_LOADED, onSiteDataLoad);
			siteData.addEventListener(SlabSiteEvent.LOGIN_FAILED, onLoginFailed);
			siteData.addEventListener(SlabSiteEvent.LOGIN_SUCCESSFUL, onLoginSuccessful);
			
			if (siteData.getSiteInfo() != null) {
				activeLoad = "home";
				sections.addSection(SlabHome);
				backgroundCheck("home");
				setTimeout(createMenu, 1500);
			}else {
				sections.showPreloader();
			}
			
		}
		private function backgroundCheck(type:String):void {
			
			var sscale:Number = 2.5;
			var prox:*;
			var inspeed:Number = .9;
			var ease:Function = Strong.easeOut;
			switch(type) {
				case "home":
					if(cbg){
						if (cbg is HomeBG) {
							TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
						}else {
							prox = cbg;
							TweenLite.to(prox, 1, { scaleX:0, scaleY:0, ease:ease, alpha:0, onComplete:background.removeChild, onCompleteParams:[prox] } );
							cbg = new HomeBG();
							cbg.scaleX = cbg.scaleY = sscale;
							cbg.alpha = 0;
							background.addChild(cbg);
							TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
						}
					}else {
						cbg = new HomeBG();
						cbg.scaleX = cbg.scaleY = sscale;
						cbg.alpha = 0;
						background.addChild(cbg);
						TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
					}
				break;
				case "artistlist":
					if(cbg){
						if (cbg is HomeBG) {
							TweenLite.to(cbg, inspeed, { scaleX:2, scaleY:2, ease:ease, alpha:1 } );
						}else {
							prox = cbg;
							TweenLite.to(prox, 1, { scaleX:0, scaleY:0, ease:ease, alpha:0, onComplete:background.removeChild, onCompleteParams:[prox] } );
							cbg = new HomeBG();
							cbg.scaleX = cbg.scaleY = sscale;
							cbg.alpha = 0;
							background.addChild(cbg);
							TweenLite.to(cbg, inspeed, { scaleX:2, scaleY:2, ease:ease, alpha:1 } );
						}
					}else {
						cbg = new HomeBG();
						cbg.scaleX = cbg.scaleY = sscale;
						cbg.alpha = 0;
						background.addChild(cbg);
						TweenLite.to(cbg, inspeed, { scaleX:2, scaleY:2, ease:ease, alpha:1 } );
					}
				break;
				case "exhibitlist":
					if(cbg){
						if (cbg is HomeBG) {
							TweenLite.to(cbg, inspeed, { scaleX:2, scaleY:2, ease:ease, alpha:1 } );
						}else {
							prox = cbg;
							TweenLite.to(prox, 1, { scaleX:0, scaleY:0, ease:ease, alpha:0, onComplete:background.removeChild, onCompleteParams:[prox] } );
							cbg = new HomeBG();
							cbg.scaleX = cbg.scaleY = sscale;
							cbg.alpha = 0;
							background.addChild(cbg);
							TweenLite.to(cbg, 1.4, { scaleX:2, scaleY:2, ease:ease, alpha:1 } );
						}
					}else {
						cbg = new HomeBG();
						cbg.scaleX = cbg.scaleY = sscale;
						cbg.alpha = 0;
						background.addChild(cbg);
						TweenLite.to(cbg, inspeed, { scaleX:2, scaleY:2, ease:ease, alpha:1 } );
					}
				break;
				case "exhibitdetails":
					if (cbg) {
						if (!(cbg is ExhibitBG)) {
							prox = cbg;
							TweenLite.to(prox, 1, { scaleX:0, scaleY:0, ease:ease, alpha:0, onComplete:background.removeChild, onCompleteParams:[prox] } );
							cbg = new ExhibitBG();
							cbg.scaleX = cbg.scaleY = sscale;
							cbg.alpha = 0;
							background.addChild(cbg);
							TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
						}
					}else {
						cbg = new ExhibitBG();
						cbg.scaleX = cbg.scaleY = sscale;
						cbg.alpha = 0;
						background.addChild(cbg);
						TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
					}
				break;
				case "privategallery":
					if (cbg) {
						if (!(cbg is PrivateBG)) {
							prox = cbg;
							TweenLite.to(prox, 1, { scaleX:0, scaleY:0, ease:ease, alpha:0, onComplete:removeTarget, onCompleteParams:[prox, background] } );
							cbg = new PrivateBG();
							cbg.scaleX = cbg.scaleY = sscale;
							cbg.alpha = 0;
							background.addChild(cbg);
							TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
						}
					}else {
						cbg = new PrivateBG();
						cbg.scaleX = cbg.scaleY = sscale;
						cbg.alpha = 0;
						background.addChild(cbg);
						TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
					}
				break;
				case "contact":
					if (cbg) {
						if (!(cbg is ContactBG)) {
							prox = cbg;
							TweenLite.to(prox, 1, { scaleX:0, scaleY:0, ease:ease, alpha:0, onComplete:background.removeChild, onCompleteParams:[prox] } );
							cbg = new ContactBG();
							cbg.scaleX = cbg.scaleY = sscale;
							cbg.alpha = 0;
							background.addChild(cbg);
							TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
						}
					}else {
						cbg = new ContactBG();
						cbg.scaleX = cbg.scaleY = sscale;
						cbg.alpha = 0;
						background.addChild(cbg);
						TweenLite.to(cbg, inspeed, { scaleX:1, scaleY:1, ease:ease, alpha:1 } );
					}
				break;
			}
		}
		private function removeTarget(targ:*, scope:*):void {
			try {
				scope.removeChild(targ);
			}catch (e:Error) {
				
			}
		}
		private function onGoHome(evt:SlabSiteEvent):void {
			activeLoad = "home";
			sections.addSection(SlabHome);
			mainMenu.unselectAll();
			removeSubElements();
			removePrivateAccess();
			revertCheck();
			randlines.onprivate = onprivate = false;
			backgroundCheck("home");
		}
		private function onExternalLink(evt:SlabSiteEvent):void {
			switch(evt.type) {
				case SlabSiteEvent.GO_TO_SILVERLENS:
					navigateToURL(new URLRequest("http://www.silverlensphoto.com/"), "_blank");
				break;
				case SlabSiteEvent.GO_TO_NEWS:
					navigateToURL(new URLRequest("slab/newsletter.html"), "_blank");
				break;
				case SlabSiteEvent.GO_TO_INKSURGE:
					navigateToURL(new URLRequest("http://www.inksurge.com/"), "_blank");
				break;
				
			}
		}
		private function onLoginFailed(evt:SlabSiteEvent):void {
			loginScreen.loginFailed();
		}
		private function onLoginSuccessful(evt:SlabSiteEvent):void {
			if (siteData.getPrivateGalleries()) {
				onCancelLogin();
				buildPrivateGallery();
			}else {
				activeLoad = "private";
			}
			
		}
		private function onLogin(evt:SlabSiteEvent):void {
			siteData.login(evt.data.uname, evt.data.pword);
		}
		private function createDisabler():void {
			disabler = new MovieClip();
			disabler.alpha = 0;
			BitmapUtils.createBounds(disabler, stage.stageWidth, stage.stageHeight, 1);
			addChild(disabler);
			TweenLite.to(disabler, .7, {alpha:.7, ease:Strong.easeOut} );
		}
		private function buildPrivateGallery():void {
			if (!onprivate) {
				onprivate = true;
				randlines.onprivate = true;
				if (logo.currentFrame == 1) {
					setTimeout(logo.gotoAndPlay, 500, "mode2");
				}
				removeSubElements();
				removePrivateAccess();
				TweenLite.to(bounds, .7, { alpha:1, ease:Strong.easeOut } );
				mainMenu.unselectAll();
				mainMenu.rollOverColor = 0xffffff;
				sections.addSection(SlabPrivateGallery);
				backgroundCheck("privategallery");
			}
		}
		private function createLoginScreen():void {
			loginScreen = new LoginScreen();
			loginScreen.x = stage.stageWidth / 2;
			loginScreen.y = stage.stageHeight / 2;
			loginScreen.description = siteData.getSiteInfo().getProperty("pgallery_login");
			loginScreen.alpha = 0;
			addChild(loginScreen);
			TweenLite.to(loginScreen, .6, { delay:.2, ease:Strong.easeOut, alpha:1} );
		}
		private function createVideoScreen(src:String):void {
			videoScreen = new SlabVideoPlayer();
			videoScreen.x = stage.stageWidth / 2;
			videoScreen.y = stage.stageHeight / 2;
			videoScreen.alpha = 0;
			addChild(videoScreen);
			TweenLite.to(videoScreen, .6, { delay:.2, ease:Strong.easeOut, alpha:1, onComplete:videoScreen.setVideoSource, onCompleteParams:[env.getSetting("baseURL")+src]} );
		}
		private function onCancelLogin(evt:SlabSiteEvent = null):void {
			TweenLite.to(loginScreen, .6, { ease:Strong.easeOut, alpha:0, onComplete:removeTarget, onCompleteParams:[loginScreen, this] } );
			TweenLite.to(disabler, .7, { delay:.4, alpha:0, ease:Strong.easeOut, onComplete:removeTarget, onCompleteParams:[disabler, this] } );
		}
		private function closeVideo(evt:MouseEvent):void {
			TweenLite.to(videoScreen, .6,  { ease:Strong.easeOut, alpha:0, onComplete:removeChild, onCompleteParams:[videoScreen] } )
			disabler.removeEventListener(MouseEvent.CLICK, closeVideo);
			TweenLite.to(disabler, .7, { delay:.4, alpha:0, ease:Strong.easeOut, onComplete:removeChild, onCompleteParams:[disabler] } );
		}
		private function onShowVideo(evt:SlabSiteEvent):void {
			createDisabler();
			disabler.useHandCursor = disabler.buttonMode = true;
			disabler.addEventListener(MouseEvent.CLICK, closeVideo);
			createVideoScreen(evt.data as String);
		}
		private function onStartLogin(evt:SlabSiteEvent):void {	
			createDisabler();
			createLoginScreen();
		}
		private function onSiteDataLoad(evt:SlabSiteEvent):void {
			revertCheck();
			randlines.onprivate = onprivate = false;
			switch(evt.type) {
				case SlabSiteEvent.ARTISTS_LOADED:
					if(activeLoad == "artists"){
						alist = sections.addSection(SlabArtistList) as SlabArtistList;
						alist.addEventListener(SlabSiteEvent.GALLERY_FROM_ARTIST, galleryFromArtist);
						backgroundCheck("artistlist");
					}
				break;
				case SlabSiteEvent.SITE_INFO_LOADED:
					sections.addSection(SlabHome);
					backgroundCheck("home");
					setTimeout(createMenu, 1500);
				break;
				case SlabSiteEvent.PUBLIC_GALLERY_LOADED:
					if(activeLoad == "exhibits"){
						var agall:SlabGallery = sections.addSection(SlabGallery);
						agall.addEventListener(SlabSiteEvent.PUBLIC_GALLERY_INFO_LOADED, onPublicGalleryInfo);
						backgroundCheck("exhibitlist");
						
					}
				break;
				case SlabSiteEvent.PRIVATE_GALLERY_LOADED:
					
					if(!onprivate){
						onCancelLogin();
						buildPrivateGallery();
					}
					
				break;
			}
		}
		private function onStageResize(evt:Event = null):void {
			try {
				disabler.width = stage.stageWidth;
				disabler.height = stage.stageHeight;
			}catch (e:Error) {
				
			}
			
			try {
				bounds.width = stage.stageWidth;
				bounds.height = stage.stageHeight;
			}catch (e:Error) {
				
			}
			try {
				loginScreen.x = stage.stageWidth / 2;
				loginScreen.y = stage.stageHeight / 2;
			}catch (e:Error) {
				
			}
			try {
				videoScreen.x = stage.stageWidth / 2;
				videoScreen.y = stage.stageHeight / 2;
			}catch (e:Error) {
				
			}
			try {
				background.x = stage.stageWidth / 2;
				background.y = stage.stageHeight / 2;
			}catch (e:Error) {
				
			}
			try {
				main.x = (stage.stageWidth/2) - (vwidth/2);
				main.y = (stage.stageHeight/2) - (vheight/2);
			}catch (e:Error) {
				
			}
		}
		private function createElements():void {
			stage.align = "TL";
			stage.scaleMode = "noScale";
			
			bounds = new MovieClip();
			BitmapUtils.createBounds(bounds, stage.stageWidth, stage.stageHeight, 1, 0x5a5959);
			bounds.alpha = 0;
			bounds.cacheAsBitmap = true;
			addChild(bounds);
			
			background = new SlabBackground();
			background.x = Math.ceil(vwidth/2);
			background.y = Math.ceil(vheight/2);
			background.cacheAsBitmap = true;
			addChild(background);
			
			randlines = new RandomLines();
			randlines.x = 100;
			randlines.y = 300;
			randlines.alpha = .9;
			main.addChild(randlines);
			
			sections = new SlabSectionManager();
			sections.x = 275;
			sections.y = 82;
			main.addChild(sections);
			
			
			
			
			
			setChildIndex(bounds, 0);
			setChildIndex(background, 1);
			setChildIndex(main, 2);
			
			logo = new SlabLogo();
			logo.x = 3;
			logo.y = 223;
			logo.alpha = 0;
			TweenLite.to(logo, .9, { alpha:1, ease:Strong.easeOut } );
			main.addChild(logo);
			
			footer = new SlabFooter();
			footer.x = vwidth;
			footer.y = vheight;
			main.addChild(footer);
			
			
		}
		private function removeSubMenu():void {
			try {
				main.removeChild(subMenu);
			}catch (e:Error) {
				
			}
		}
		private function removePrivateAccess():void {
			try {
				if(privateAccessButton && main.contains(privateAccessButton)){
					TweenLite.to(privateAccessButton, .4, { alpha:0, ease:Strong.easeOut, onComplete:removeTarget, onCompleteParams:[privateAccessButton, main] } );
				}
			}catch (e:Error) {
				
			}
		}
		private function removeSubElements():void {
			
			if(subMenu){
				TweenLite.to(subMenu, .4, { alpha:0, ease:Strong.easeOut, onComplete:removeSubMenu } );
			}
		}
		private function createContactScreen():void {
			
			sections.addSection(SlabContact);
			revertCheck();
			randlines.onprivate = onprivate = false;
			backgroundCheck("contact");

		}
		private function createSubMenu():void {
			var tmp = new AnimatedItem(new Object(), new TextFormat());
			tmp = null;
			
			var menuStyle:Object = {embedFonts:true, autoSize:"left", border:false, background:false, backgroundColor:0x222222, antiAliasType:AntiAliasType.NORMAL, gridFitType:GridFitType.PIXEL};
			var menuFontFormat:TextFormat = new TextFormat();
			var fontObj:Object = getDefinitionByName("pixelate");
			menuFontFormat.color = 0x999999;
			menuFontFormat.font = new fontObj().fontName;
			menuFontFormat.size = 10;
			subMenu = new MenuComponent("as3.common.ui.menu.AnimatedItem");
			subMenu.slow_generation = true;
			subMenu.y = 350;
			subMenu.orientation = "vertical";
			subMenu.labelField = "menu_label";
			subMenu.decoration = "subButtonOver";
			subMenu.outdecoration = "subButtonOut";
			subMenu.menuTextFieldStyle = menuStyle;
			subMenu.menuFontStyle = menuFontFormat;
			subMenu.rollOverColor = onprivate ? 0xffffff : 0x000000;
			subMenu.upperCaseLabel = true;
			subMenu.ypad = -3;
			subMenu.x = 65;
			subMenu.selectFirstItem = false;
			subMenu.addEventListener(MenuComponentEvent.CLICK, subMenuClicked);
			main.addChild(subMenu);
			subMenu.items = StaticMenuSet.SubMenu().data_record;
			if(!onprivate){
				createPrivateLogin();
			}
		}
		private function createPrivateLogin():void {
			try {
				removeChild(privateAccessButton);
			}catch (e:Error) {
				
			}
			privateAccessButton = new PrivateAccessButton();
			privateAccessButton.alpha = 0;
			privateAccessButton.description = siteData.getSiteInfo().getProperty("pgallery_access");
			privateAccessButton.x = logo.x + 20;
			privateAccessButton.y = logo.y + 250;
			main.addChild(privateAccessButton);
			TweenLite.to(privateAccessButton, .7, { alpha:1, ease:Strong.easeOut } );
			
		}
		private function revertCheck():void {
			if (onprivate) {
				mainMenu.rollOverColor = 0x555555;
				setTimeout(logo.gotoAndPlay, 300, "mode1");
				TweenLite.to(bounds, .7, { alpha:0, ease:Strong.easeOut } );
			}
			try {
				subMenu.rollOverColor = onprivate ? 0xffffff : 0x000000;
			}catch (e:Error) {
				
			}
		}
		private function galleryFromArtist(evt:SlabSiteEvent):void {
			mainMenu.unselectAll();
			removeSubElements();
			var agall:SlabGallery = sections.addSection(SlabGallery, { defaultInfo:evt.data } );
			agall.addEventListener(SlabSiteEvent.PUBLIC_GALLERY_INFO_LOADED, onPublicGalleryInfo);
			backgroundCheck("exhibitdetails");
			randlines.onprivate = onprivate = false;
		}
		private function onPublicGalleryInfo(evt:SlabSiteEvent):void {
			mainMenu.unselectAll();
			removeSubElements();
			randlines.onprivate = onprivate = false;
			backgroundCheck("exhibitdetails");
		}
		private function subMenuClicked(evt:MenuComponentEvent):void {
			if (!onprivate) {
				if(!main.contains(privateAccessButton)){
					createPrivateLogin();
				}
			}
			revertCheck();
			randlines.onprivate = onprivate = false;
			
			switch(evt.data.menu_label.toString()) {
				case "VIEW EXHIBITS":
					activeLoad = "exhibits";
					if (siteData.getPublicGalleries() != null) {
						var agall:SlabGallery = sections.addSection(SlabGallery);
						agall.addEventListener(SlabSiteEvent.PUBLIC_GALLERY_INFO_LOADED, onPublicGalleryInfo);
						backgroundCheck("exhibitlist");
					}else {
						sections.showPreloader();
					}
				break;
				case "VIEW BY ARTIST":
					activeLoad = "artists";
					if (siteData.getArtistList() != null) {
						alist = sections.addSection(SlabArtistList) as SlabArtistList;
						alist.addEventListener(SlabSiteEvent.GALLERY_FROM_ARTIST, galleryFromArtist);
						backgroundCheck("artistlist");
					}else {
						sections.showPreloader();
					}
				break;
			}
			
		}
		private function createMenu():void {
			var tmp = new AnimatedItem(new Object(), new TextFormat());
			tmp = null;
			
			mainMenu = new MenuComponent("as3.common.ui.menu.AnimatedItem");
			mainMenu.slow_generation = true;
			var menuStyle:Object = {embedFonts:true, autoSize:"left", border:false, background:false, backgroundColor:0x222222, antiAliasType:AntiAliasType.NORMAL, gridFitType:GridFitType.PIXEL};
			var menuFontFormat:TextFormat = new TextFormat();
			var fontObj:Object = getDefinitionByName("pixelate");
			menuFontFormat.color = 0x999999;
			menuFontFormat.font = new fontObj().fontName;
			menuFontFormat.size = 10;
			mainMenu.x = 52;
			mainMenu.y = 320;
			mainMenu.selectFirstItem = false;
			mainMenu.orientation = "horizontal";
			mainMenu.labelField = "menu_label";
			mainMenu.menuTextFieldStyle = menuStyle;
			mainMenu.menuFontStyle = menuFontFormat;
			mainMenu.rollOverColor = 0x555555;
			mainMenu.upperCaseLabel = true;
			mainMenu.xpad = 15;
			mainMenu.items = StaticMenuSet.MainMenu().data_record;
			main.addChild(mainMenu);
			mainMenu.addEventListener(MenuComponentEvent.CLICK, mainMenuClicked);
		}
		private function mainMenuClicked(evt:MenuComponentEvent):void {
			try{
				if (subMenu && contains(subMenu)) {
					removeSubElements();
				}
			}catch (e:Error) {
					
			}
			switch(evt.data.menu_label.toLowerCase()) {
				case "gallery":
					createSubMenu();
				break;
				case "contact":
					createContactScreen();
				break;
				case "news":
					mainMenu.unselectAll();
					DispatchChannel.getChannel().dispatchEvent(new SlabSiteEvent(SlabSiteEvent.GO_TO_NEWS));
				break;
			}
		}
	}
}